<template>
		<view class="cu-card" >
			<view v-if="item!=null" class="cu-item shadow bg-white padding">
				<view class="padding margin-lr-xs flex justify-center">
						<view class="nav-avatar round lg margin-lr-xs" 
						v-if="item.tzPtCode.user.avatarurl" 
						:style="[{ backgroundImage:'url(' +item.tzPtCode.user.avatarurl + ')' }]">
						</view>
						<view class="nav-avatar round lg margin-lr-xs" 
						v-if="item.tyPtCode.length>0 && item.tyPtCode[0].user.avatarurl" 
						:style="[{ backgroundImage:'url(' +item.tyPtCode[0].user.avatarurl+ ')' }]">
						</view>
						<view class="nav-avatar round lg margin-lr-xs" v-else :style="[{ backgroundImage:'url(' +'http://pic.51yuansu.com/pic2/cover/00/39/75/5812f9df430bf_610.jpg'+ ')' }]"></view>
						<view class="nav-avatar round lg margin-lr-xs" :style="[{backgroundImage:'url(' +'http://pic.51yuansu.com/pic2/cover/00/39/75/5812f9df430bf_610.jpg'+ ')' }]"></view>
				</view>
				<view class="flex justify-center">
					<view class="example-body">
						<uniCountdown :show-day="false" :hour="item.hour" :minute="item.minute" :second="item.second" color="#333a3e"/>
					</view>
				</view>
				<view class="flex justify-center margin-top">
					<view class="cu-btn bg-red radius"  @tap="getShareCode()">分享拼单</view>
				</view>				
				</view>
			
		<view v-else class="cu-item shadow bg-white">
			<view class="justify-center align-center flex padding-xl">
				<view class="text-bold" style="font-size: 18px;">恭喜哦，完成拼单！</view>
			</view>
		</view>	
			
			
		</view>		
</template>

<script>
	import uniCountdown from '../../../component/uniCountdown.vue'
	import moment from "moment";
	moment.locale("zh-cn");
	export default{
		components: {
			uniCountdown
		},
		data(){
			return{
				ptCode:0,
				item:[]
			}
		},
		onLoad(option) {
			this.ptCode=option.ptCode;
			console.log("当前拼单的ptCode"+this.ptCode)
			this.getCollage();
		},
		methods:{
			getCollage(){//获取参与的拼团信息
				this.request({
					url:this.apiServer+'/ptInfo/findAllPtByPtCode?limit=5&skip=0&ptCode='+this.ptCode
				}).then(res=>{
					console.log(res)
					if(res.data.length>0){
                        res.data.forEach(v=>{
						this.collageNum=1+v.tyPtCode.length+this.collageNum						
						//console.log(this.collageNum)
						let dura = moment(v.tzPtCode.endTime).format('x') - moment(this.now).format('x');
						var du=moment.duration(dura, 'ms');
						//console.log(du.days()+":"+du.hours()+":"+du.minutes()+":"+du.seconds())
						if(du.hours()>=0&&du.minutes()>=0&&du.seconds()>=0)
						{
						    v.hour=du.hours();
						    v.minute=du.minutes();
						    v.second=du.seconds();					
						}
					}
				    );					
					    this.item=res.data[0];
					console.log("xx:"+this.item.length)
					}
                    else 
					{
						this.item=null;
					console.log("xx:"+this.item.length)	
					}
					
				})
			},
			getShareCode()
			{
				//console.log("成功获取邀请码"+e)
				uni.setClipboardData({
				    data: this.ptCode,
				    success: function () {
				        console.log('success');
				    }
				});
			},
		}
	}
</script>

<style>
	.nav-avatar.lg {
		width: 96upx;
		height: 96upx;
		font-size: 2em;
	}
	.nav-avatar {
		font-variant: small-caps;
		margin: 0;
		padding: 0;
		display: inline-flex;
		text-align: center;
		justify-content: center;
		align-items: center;
		background-color: #ccc;
		color: #ffffff;
		white-space: nowrap;
		position: relative;
		width: 64upx;
		height: 64upx;
		background-size: cover;
		background-position: center;
		vertical-align: middle;
		font-size: 1.5em;
	}
</style>
